package com.redis.publish;

import redis.clients.jedis.Jedis;

/**
 * 订阅和取消订阅线程类
 */
public class SubscribeThread extends Thread {
	private Jedis jedis;
	private MyJedisPubSub myJedisPubSub;
	private String[] channels;
	
	public SubscribeThread(String clientName, String[] channels) {
		this.jedis = new Jedis("127.0.0.1", 6379);
		this.myJedisPubSub = new MyJedisPubSub(clientName);
		this.channels = channels;
	}
	
	@Override
	public void run() {
		jedis.subscribe(myJedisPubSub, channels);
	}
	
	public void unsubscribe(String[] channels) {
		myJedisPubSub.unsubscribe(channels);
	}
	
}
